package org.example.frw.response;

import lombok.Data;

@Data
public class ResponseResult<T> {
    /**
     * 响应状态码，0是正常，非0表示异常
     */
    private int code;
    /**
     * success or ...
     */
    private String type;
    /**
     * 异常信息
     */
    private String message;
    /**
     * 响应数据
     */
    private T result;

    public static <T> ResponseResult<T> success() {
        return success(0, null, null);
    }

    public static <T> ResponseResult<T> success(T data) {
        return success(0, null, data);
    }

    public static <T> ResponseResult<T> fail(int code, String domain, String message) {
        ResponseResult<T> r = new ResponseResult<>();
        r.setCode(code);
        r.setMessage(message);
        r.setResult(null);
        r.setType(domain);
        return r;
    }

    public static <T> ResponseResult<T> success(int status, String message, T data) {
        ResponseResult<T> r = new ResponseResult<>();
        r.setCode(status);
        r.setMessage(message);
        r.setResult(data);
        r.setType("success");
        return r;
    }

}

